Skip to content

fix: increase Hyperlight I/O buffer for large hostfs writes - #81

Merged
danbugs merged 3 commits into
mainfrom
fix/io-buffer-size
May 22, 2026
Merged

fix: increase Hyperlight I/O buffer for large hostfs writes#81
danbugs merged 3 commits into
mainfrom
fix/io-buffer-size

Conversation

@danbugs

@danbugs danbugs commented May 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The Hyperlight SDK defaults shared-memory I/O stacks to 16 KiB each, but a single hostfs write chunk (32 KiB) expands to ~44 KiB after base64 + JSON + FlatBuffer encoding, overflowing the output stack and failing with EIO
  • Set the default I/O buffer size to 128 KiB, sufficient for any single-chunk RPC with headroom
  • Expose io_buffer_size on VmConfig and SandboxBuilder so embedders can tune it
  • Add runtime_filesystem_large_binary_write integration test (40 KiB binary blob)

Test plan

  • runtime_filesystem_large_binary_write passes
  • Existing filesystem tests unaffected
  • cargo check clean

The Hyperlight SDK defaults input/output shared-memory stacks to 16 KiB
each. The hostfs VFS layer chunks writes at 32 KiB, but after base64
encoding + JSON envelope + FlatBuffer framing, a single chunk occupies
~44 KiB — overflowing the 16 KiB output stack and causing hcall_push
to fail with EIO on writes exceeding ~12 KiB.

Set the I/O buffer size to 128 KiB (sufficient for any single-chunk RPC
with headroom) and expose it as a configurable field on VmConfig and
SandboxBuilder so embedders can tune it for their workload.

Signed-off-by: danbugs <danilochiarlone@gmail.com>
Copilot AI review requested due to automatic review settings May 22, 2026 19:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR increases the default Hyperlight shared-memory I/O buffer sizes to prevent host function call payload overflows during large hostfs write RPCs, and exposes a knob so embedders can tune the buffer size.

Changes:

  • Add io_buffer_size to VmConfig and plumb it through to Hyperlight SandboxConfiguration input/output data sizes.
  • Add SandboxBuilder::io_buffer_size(...) for configuring the shared-memory I/O buffers.
  • Add an integration test that writes a >32 KiB binary file via hostfs and verifies its contents on the host.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
host/tests/pyhl_runtime.rs Adds a runtime integration test covering large binary writes through hostfs.
host/src/lib.rs Introduces configurable I/O buffer sizing and increases the default to 128 KiB.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread host/src/lib.rs
Comment on lines 528 to 532
pub struct VmConfig {
pub heap_size: u64,
pub stack_size: u64,
pub io_buffer_size: usize,
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — added #[non_exhaustive] to VmConfig.

Comment thread host/src/lib.rs
Comment on lines 572 to +576
fn sandbox_config(&self) -> SandboxConfiguration {
let mut cfg = SandboxConfiguration::default();
cfg.set_heap_size(self.heap_size);
cfg.set_input_data_size(self.io_buffer_size);
cfg.set_output_data_size(self.io_buffer_size);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-existing issue — stack_size predates this PR. Tracked separately.

Comment on lines +303 to +310
let timing = rt
.run_code("with open('/host/big.bin', 'wb') as f: f.write(b'x' * 40000)")
.unwrap();
assert_eq!(timing.exit_code, 0);

let data = std::fs::read(tmp.join("big.bin")).unwrap();
assert_eq!(data.len(), 40000);
assert!(data.iter().all(|&b| b == b'x'));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — using 40 * 1024 now.

danbugs added 2 commits May 22, 2026 19:06
- Mark VmConfig as #[non_exhaustive] to prevent semver breakage when
  new fields are added
- Use explicit 40 KiB (40 * 1024) in the large binary write test to
  match the PR description and make the boundary condition clearer

Signed-off-by: danbugs <danilochiarlone@gmail.com>
Signed-off-by: danbugs <danilochiarlone@gmail.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux Benchmarks

Details
Benchmark suite Current: dab60b0 Previous: 20ccc2d Ratio
hello_world (median) 20 ms 20 ms 1
pandas (median) 110 ms 110 ms 1
density (per VM) 7 MB 7 MB 1
snapshot (disk) 385 MiB 385 MiB 1

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows Benchmarks

Details
Benchmark suite Current: dab60b0 Previous: 20ccc2d Ratio
hello_world (median) 267 ms 261 ms 1.02
pandas (median) 896 ms 800 ms 1.12
density (per VM) 6 MB 6 MB 1
snapshot (disk) 392 MiB 392 MiB 1

This comment was automatically generated by workflow using github-action-benchmark.

@danbugs
danbugs merged commit 7162172 into main May 22, 2026
79 checks passed
@danbugs
danbugs deleted the fix/io-buffer-size branch May 22, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants